import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
import SysUser from '../../entities/users/sys-user.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import { HashPasswordMiddleware } from 'src/middlewares/hash-password.middleware';
@Module({
  // 调用此方法在数据库中生成了映射类
  imports: [TypeOrmModule.forFeature([SysUser])],
  controllers: [UsersController],
  providers: [UsersService],
  exports: [UsersService], //在这进行抛出别的地方才能用
})
export class UsersModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(HashPasswordMiddleware).forRoutes('users/register'); //对应的是某个路由下才会生效 其他的路由就不会影响了
  }
}
